package com.zrrd.sort;

import java.util.Arrays;

public class QuickSort {
    public void quickSort(int[] array) {
        quickSortInner(array, 0, array.length - 1);
    }

    public void quickSortInner(int[] array, int start, int end) {
        if (start > end) {
            return;
        }
        int i = start;
        int j = end;
        int temp;
        while (i < j) {
            while (array[i] <= array[j] && i < j) {
                i++;
            }
            if (i < j) {
                temp = array[i];
                array[i] = array[j];
                array[j] = temp;

            }
            while (array[j] >= array[i] && i < j) {
                j--;
            }
            if (i < j) {
                temp = array[i];
                array[i] = array[j];
                array[j] = temp;

            }
        }
        quickSortInner(array, start, i - 1);
        quickSortInner(array, i + 1, end);
    }

    public static void main(String[] args) {
        QuickSort qs = new QuickSort();
        int[] array = new int[]{4, 2, 1, 0, 6, 7, 9, 8, 5};
        qs.quickSort(array);
        System.out.println(Arrays.toString(array));
    }
}
